/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */

package com.hibernate.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


@Entity
@Table(name = "AD_SITE_SIZE")
public class AdSiteSize extends BaseEntity implements java.io.Serializable{
	private static final long serialVersionUID = 5454155825314635342L;
	
	//alias
	public static final String TABLE_ALIAS = "AdSiteSize";
	public static final String ALIAS_ID = "id";
	public static final String ALIAS_USER_ID = "userId";
	public static final String ALIAS_WIDTH = "width";
	public static final String ALIAS_HEIGHT = "height";
	public static final String ALIAS_STATUS = "status";
	
	//date formats
	

	//可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	//columns START
	
	private Long id;
	
	private Long userId;
	@NotNull 
	private java.lang.Long width;
	@NotNull 
	private java.lang.Long height;
	@NotBlank @Length(max=1)
	private java.lang.String status;
	
	@NotNull
	private java.lang.Long poolId;
	//columns END


	public AdSiteSize(){
	}

	public AdSiteSize(
		Long id
	){
		this.id = id;
	}

	

	public void setId(Long value) {
		this.id = value;
	}
	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getId() {
		return this.id;
	}
	
	@Column(name = "USER_ID", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public Long getUserId() {
		return this.userId;
	}
	
	public void setUserId(Long value) {
		this.userId = value;
	}
	
	@Column(name = "POOL_ID", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
	public Long getPoolId() {
		return this.poolId;
	}
	
	public void setPoolId(Long value) {
		this.poolId = value;
	}
	
	@Column(name = "WIDTH", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
	public java.lang.Long getWidth() {
		return this.width;
	}
	
	public void setWidth(java.lang.Long value) {
		this.width = value;
	}
	
	@Column(name = "HEIGHT", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
	public java.lang.Long getHeight() {
		return this.height;
	}
	
	public void setHeight(java.lang.Long value) {
		this.height = value;
	}
	
	@Column(name = "STATUS", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
	public java.lang.String getStatus() {
		return this.status;
	}
	
	public void setStatus(java.lang.String value) {
		this.status = value;
	}
	
	
	@SuppressWarnings("rawtypes")
	private Set adSites = new HashSet(0);
	public void setAdSites(Set<AdSite> adSite){
		this.adSites = adSite;
	}
	
	@SuppressWarnings("unchecked")
	@OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "adSiteSize")
	public Set<AdSite> getAdSites() {
		return adSites;
	}
	
	private AcctUser acctUser;
	public void setAcctUser(AcctUser acctUser){
		this.acctUser = acctUser;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumns({
		@JoinColumn(name = "USER_ID",nullable = false, insertable = false, updatable = false) 
	})
	public AcctUser getAcctUser() {
		return acctUser;
	}

	public String toString() {
		return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
			.append("Id",getId())
			.append("UserId",getUserId())
			.append("Width",getWidth())
			.append("Height",getHeight())
			.append("Status",getStatus())
			.toString();
	}
	
	public int hashCode() {
		return new HashCodeBuilder()
			.append(getWidth()).append(getHeight())
			.toHashCode();
	}
	
	public boolean equals(Object obj) {
		if(obj instanceof AdSiteSize == false) return false;
		if(this == obj) return true;
		AdSiteSize other = (AdSiteSize)obj;
		return new EqualsBuilder()
			.append(getWidth() ,other.getWidth()).append(getHeight() ,other.getHeight())
			.isEquals();
	}
	
	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return "广告位尺寸";
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return getId();
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return "AD_SITE_SIZE" +getId();
	}
}

